package com.josn.service.impl;

import com.josn.mapper.CategoryMapper;
import com.josn.pojo.Category;
import com.josn.service.CategoryService;
import com.josn.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;

    //新增文章
    @Override
    public void add(Category category){
        Map<String,Object> map= ThreadLocalUtil.get();
        Integer user_id=(Integer) map.get("id");
        category.setCreate_user(user_id);
        categoryMapper.add(category);
    }

    //获取文章分类信息
    @Override
    public List<Category> list(){
        Map<String,Object> map= ThreadLocalUtil.get();
        Integer user_id=(Integer) map.get("id");
        return categoryMapper.list(user_id);
    }

    //获取文章分类详情
    @Override
    public Category findById(Integer id){
        return categoryMapper.findById(id);
    }

    //更新文章分类
    @Override
    public void update(Category category){
        categoryMapper.update(category);
    }

    //删除文章分类
    @Override
    public void deleteById(Integer id){
        categoryMapper.deleteById(id);
    }
}
